package org.avapir.snake;

import java.lang.reflect.Field;

/**
 * 
 * @author Alpen Ditrix
 *
 */
public class Loader implements Constants {

	public static void initialization() {
		loadConsts();
		loadSprites();
		loadGame();
		loadDebug();
		loadPainter();
	}

	private static void loadConsts() {
		for (Field f : Constants.class.getFields()) {
			if (f.equals(null))
				throw new RuntimeException("null-const lolwhat?");
		}
	}

	private static void loadDebug() {
		Debug.longSleepsCounter = 0;
		Debug.shortSleepsCounter = 0;
		Debug.sleepTime = 0;
		Debug.workTime = 0;
	}

	private static void loadGame() {
		Game.newGame();
		Game.readRecordScore();
		Game.game.addKeyListener(new KeyInputHandler());
		Game.createSnakes();
		Game.createFood();
		Game.updateSpeed();
	}

	private static void loadPainter() {
		Painter.snakes = Game.snakes;
		Painter.game = Game.game;
		Painter.bStrategy = Game.game.getBufferStrategy();
	}

	private static void loadSprites() {
		for (int i = 0; i < IMAGES_AMOUNT; i++) {
			Game.sprites.put(Integer.toString(i),
					new Sprite("res/" + Integer.toString(i) + ".jpg"));
		}
	}
}
